<?php
/**
 * 供给人脸识别的接口
 */
namespace app\index\controller;
use think\Controller;
use think\Request;
use think\Db;
class Api extends Controller{
	public function _initialize(){
		header("Access-Control-Allow-Origin: *");
    	header("Access-Control-Allow-Methods: OPTIONS,HEAD,GET,POST,PUT,PATCH,DELETE");
   		header("Access-Control-Allow-Headers:Content-Type,Content-Range,Content-Disposition");
   		set_time_limit(0);
	}
	/**
	 * 验证租客手机号码、身份证号
	 */
	public function check_tenant(){
   		$param=request()->param();
   		$val=validate('Face');
		if(!$val->scene('check_user')->check($param)) return rel(-1,$val->getError());
		
   		$user=Db::name('users')->where(['phone'=>$param['phone'],'idcard'=>$param['idcard'],'type'=>2])->find();
   		if(!$user) return rel(-1,'手机号码或身份证不匹配');
   		
   		$map['c.tenant_id']=$user['id'];
   		$map['c.stat']=2;
   		
   		$rel=Db::name('contract')->alias('c')
   		->field('c.id as contract_id,u.id as uid,u.nickname,u.name,u.idcard,u.phone,h.tit,p.id as pid,p.tit as ptit,p.decl,p.address')
   		->join('users u','c.tenant_id=u.id')
   		->join('house h','c.house_id=h.id')
   		->join('plot p','h.plot_id=p.id')
   		->where($map)
   		->find();
   		
   		if(!$rel){
   			return rel(-1,'该租客不满足要求');
   		}else{
   			return rel(1,'该租客验证成功');
   		}
	}
	/**
	 * 验证业主手机号、身份证
	 */
	public function check_ower(){
		$param=request()->param();
   		$val=validate('Face');
		if(!$val->scene('check_user')->check($param)) return rel(-1,$val->getError());
		
   		$user=Db::name('users')->where(['phone'=>$param['phone'],'idcard'=>$param['idcard'],'type'=>3])->find();
   		if(!$user) return rel(-1,'手机号码或身份证不匹配');
   		
   		$rel=Db::name('users')->alias('u')
   		->field('u.id as ower_id,u.nickname,u.name,u.idcard,u.phone,h.tit as htit,p.tit as ptit')
   		->join('house h','c.house_id=h.id')
   		->join('plot p','h.plot_id=p.id')
   		->where($map)
   		->find();
   		
   		if(!$rel){
   			return rel(-1,'该业主不满足要求');
   		}else{
   			return rel(1,'该业主验证成功');
   		}
	}
	/**
	 * 
	 */
}